package keeto.com.vn.bms.network.task;

import java.io.IOException;

import keeto.com.vn.bms.config.IBMSCore;
import keeto.com.vn.bms.network.request.SentStatusScheduleRequest;
import keeto.com.vn.bms.network.response.SentStatusScheduleReponse;
import keeto.com.vn.bms.utils.BMSListener;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;

public class TaskSentStatusSchedule extends AbstractTask{
	private String ID;
	private String Status;
	private String AuthKey;
	
	public TaskSentStatusSchedule(BMSListener listener, IBMSCore core,
			String iD, String status, String authKey) {
		super(listener, core);
		ID = iD;
		Status = status;
		AuthKey = authKey;
	}

	@Override
	public void run() throws ClientProtocolException, JSONException, IOException {
		SentStatusScheduleRequest request = new SentStatusScheduleRequest();
		request.setAuthKey(AuthKey);
		request.setID(ID);
		request.setStatus(Status);
		SentStatusScheduleReponse reponse = protocol.sentStatusSchedule(request);
		for (BMSListener mListener : listener){
			mListener.finishSentStatusSchedule(reponse.getReturnCode(),reponse.getResultMsg(), reponse.getStatus());
		}
	}

	@Override
	public void timeoutCallback() {
		for (BMSListener mListener : listener){
			mListener.finishSentStatusSchedule(protocol.STATUS_CODE_GENERIC_FAIL_CONECTTION,"","");
		}
	}

}
